package UI;

import data_management.InvDBManager;
import data_management.Main;
import data_management.PermissionManager;
import junit.framework.TestCase;

public class SignInInterfaceTest extends TestCase {

	public void testInitialize()  {
		
		SignInInterface.getInstance().initialize();
	}
	
	/**
	 * Make sure someone with incorrect credentials does not get logged in
	 */
	public void testIncorrectSignIn() {
		
		InvDBManager.getInstance().initializeDatabase();
		new Main();
		SignInInterface si = SignInInterface.getInstance();
		si.username = "incorrectnameohno";
		si.password = "qwertyuiop";
		si.attemptLogin();
		
		assertTrue(PermissionManager.getInstance().desktopUser == null);
		assertTrue(SignInInterface.getInstance().getParent() != null);
	}
	
	/**
	 * Check that someone with valid credentials can log in
	 */
	public void testCorrectSignIn() {
		
		InvDBManager.getInstance().initializeDatabase();
		new Main();
		SignInInterface si = SignInInterface.getInstance();
		si.username = "j";
		si.password = "j";
		si.attemptLogin();
		
		assertTrue(PermissionManager.getInstance().desktopUser != null);
		assertTrue(SignInInterface.getInstance().getParent() == null);
	}
	
	/**
	 * Tests that the screen gets transitioned out of the login screen
	 */
	public void testPerformLogin() {
		InvDBManager.getInstance().initializeDatabase();
		new Main();
		SignInInterface si = SignInInterface.getInstance();
		si.performLogin();
		
		assertTrue(si.getParent() == null);
	}
	
}
